"""
flatMap算子
    计算逻辑和map一样
    可以比map多出，解除一层嵌套的功能
"""
from pyspark import SparkConf, SparkContext
import os
os.environ['PYSPARK_PYTHON'] = "F:/Python/python3.7.7/python.exe"
conf = SparkConf().setMaster("local[*]").setAppName("test_spark")
sc = SparkContext(conf=conf)

# 准备一个RDD
rdd = sc.parallelize(["itheima itcast 666", "itheima itheima itcast", "python itheima"])

# 需求，将RDD数据里面的一个个单词提取出来
rdd3 = rdd.map(lambda x: x.split(" "))
print(rdd3.collect())  # [['itheima', 'itcast', '666'], ['itheima', 'itheima', 'itcast'], ['python', 'itheima']]
rdd2 = rdd.flatMap(lambda x: x.split(" "))  # ['itheima', 'itcast', '666', 'itheima', 'itheima', 'itcast', 'python', 'itheima']
print(rdd2.collect())
